package com.zhuo.project.hms.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhuo.framework.aspectj.lang.annotation.Log;
import com.zhuo.framework.aspectj.lang.enums.BusinessType;
import com.zhuo.project.hms.domain.ZzClinicRefDepot;
import com.zhuo.project.hms.service.IZzClinicRefDepotService;
import com.zhuo.framework.web.controller.BaseController;
import com.zhuo.framework.web.domain.AjaxResult;
import com.zhuo.common.utils.poi.ExcelUtil;
import com.zhuo.framework.web.page.TableDataInfo;

/**
 * 诊所仓库关系信息Controller
 * 
 * @author zhuo
 * @date 2020-03-21
 */
@RestController
@RequestMapping("/hms/depot")
public class ZzClinicRefDepotController extends BaseController
{
    @Autowired
    private IZzClinicRefDepotService zzClinicRefDepotService;

    /**
     * 查询诊所仓库关系信息列表
     */
    @PreAuthorize("@ss.hasPermi('hms:depot:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZzClinicRefDepot zzClinicRefDepot)
    {
        startPage();
        List<ZzClinicRefDepot> list = zzClinicRefDepotService.selectZzClinicRefDepotList(zzClinicRefDepot);
        return getDataTable(list);
    }

    /**
     * 导出诊所仓库关系信息列表
     */
    @PreAuthorize("@ss.hasPermi('hms:depot:export')")
    @Log(title = "诊所仓库关系信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZzClinicRefDepot zzClinicRefDepot)
    {
        List<ZzClinicRefDepot> list = zzClinicRefDepotService.selectZzClinicRefDepotList(zzClinicRefDepot);
        ExcelUtil<ZzClinicRefDepot> util = new ExcelUtil<ZzClinicRefDepot>(ZzClinicRefDepot.class);
        return util.exportExcel(list, "depot");
    }

    /**
     * 获取诊所仓库关系信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hms:depot:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zzClinicRefDepotService.selectZzClinicRefDepotById(id));
    }

    /**
     * 新增诊所仓库关系信息
     */
    @PreAuthorize("@ss.hasPermi('hms:depot:add')")
    @Log(title = "诊所仓库关系信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZzClinicRefDepot zzClinicRefDepot)
    {
        return toAjax(zzClinicRefDepotService.insertZzClinicRefDepot(zzClinicRefDepot));
    }

    /**
     * 修改诊所仓库关系信息
     */
    @PreAuthorize("@ss.hasPermi('hms:depot:edit')")
    @Log(title = "诊所仓库关系信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZzClinicRefDepot zzClinicRefDepot)
    {
        int ret = zzClinicRefDepotService.updateZzClinicRefDepot(zzClinicRefDepot);
        if(ret <0){
            return AjaxResult.error("修改" + zzClinicRefDepot.getClinicCode() + " 诊所编码 " + zzClinicRefDepot.getDepotCode() + "仓库失败，参数键名已存在");
        }
        return toAjax(ret);
    }

    /**
     * 删除诊所仓库关系信息
     */
    @PreAuthorize("@ss.hasPermi('hms:depot:remove')")
    @Log(title = "诊所仓库关系信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zzClinicRefDepotService.deleteZzClinicRefDepotByIds(ids));
    }
}
